# 去掉带有公式的行
# encoding=utf-8
# 经过测试此方法多线程和单线程速度差不多
import re
from concurrent.futures import ThreadPoolExecutor
import threading

lock = threading.Lock()  # 申请一把锁


def write(line, fout, i):
    if i % 100 == 0:
        print("执行到了：%s 行" % i)
    lock.acquire()  # 加锁
    fout.write('%s' % line)
    lock.release()  # 释放锁


def handle(infile, outfile):
    fp = open(infile, 'r', encoding='utf-8')
    fout = open(outfile, 'a', encoding='utf-8')
    fool = ThreadPoolExecutor(10)  # 线程池里有20个线程
    i = 0
    for line in fp.readlines():
        i += 1
        if bool(re.search("[-\d()*+/=\.]{15,}", line)):
            continue
        fool.submit(write, line, fout, i)

    fp.close()
    fout.close()


if __name__ == '__main__':
    infile = '../out3.tsv'
    outfile = '../out3_noformula.tsv'
    handle(infile, outfile)
